import time
from threading import Thread


class PrintingTask:
    def __init__(self, name, char, n=None, interv=0.2):
        self._running = True
        self.name = name
        self.char = char
        self.n = n
        self.interv = interv

    def stop(self):
        self._running = False

    def run(self):
        while self._running:
            if self.n is not None:
                if self.n <= 0:
                    break
                self.n -= 1
            print(self.char, end='', flush=True)
            time.sleep(self.interv)
        print(f'{self.name} over.')


c1 = PrintingTask('t1', '1', interv=0.1)
t1 = Thread(target=c1.run, args=())
t1.start()

time.sleep(1)
print('Stopping t1 ...')
c1.stop()
